home *** CD-ROM | disk | FTP | other *** search
-
-
- #include <stdio.h>
- #include <string.h>
- #include "cb.h"
-
- #define NST 60
-
- main(argc,argv)
- int argc;
- char *argv[];
- {
- FILE *fp;
- FILE *op;
- FILE *sp[NST];
- long pos;
- char str[256];
- char tmp[256];
- char *f[20]; /* fields */
- char *p;
- int i;
- int recs;
-
- static char *names[] = {
-
- "AA","AE","AK","AL","AP","AR","AS","AZ","CA","CO","CT",
- "DC","DE","FL","GA","GU","HI","IA","ID","IL","IN","KS",
- "KY","LA","MA","MD","ME","MI","MN","MO","MP","MS","MT",
- "NC","ND","NE","NH","NJ","NM","NV","NY","OH","OK","OR",
- "PA","PR","RI","SC","SD","TN","TX","UM","UT","VA","VI",
- "VT","WA","WI","WV","WY"
-
- };
-
- for (i=0; i<NST; i++)
- {
- sprintf(str,"states/%s",names[i]);
- if ((sp[i]=fopen(str,"w")) == NULL)
- {
- printf ("\nError opening %s\n",str);
- exit(0);
- }
- }
-
- if (!argv[1])
- {
- printf("Usage: %s dbase_name\n",argv[0]);
- exit(1);
- }
- if ((fp=fopen(argv[1],"r")) == NULL)
- {
- printf("Error opening %s\n",argv[1]);
- exit(1);
- }
-
- recs = 0;
- while (!feof(fp))
- {
- memset(str,0,sizeof(str));
- memset(tmp,0,sizeof(tmp));
- memset(f,0,sizeof(f));
-
- fgets(str,sizeof(str),fp);
- if ((int)strlen(str) < 10)
- continue;
-
- strcpy(tmp,str);
- mk_fields(tmp,f);
-
- for (i=0; i<NST; i++)
- {
- if (!strcmp(f[MAIL_ST],names[i]))
- break;
- }
-
- if (i == NST)
- {
- printf("Unknown entry: \n%s\n",str);
- continue;
- }
-
- if (f[P_CALL])
- while(f[P_CALL][0] == ' ')
- f[P_CALL]++;
-
- if (f[P_CALL][0])
- {
-
- fprintf(sp[i],"%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s\n",
- f[CALL],
- f[LNAME],
- f[FNAME],
- f[MI],
- f[JR],
- f[DOB],
- f[MAIL_STR],
- f[MAIL_CITY],
- f[MAIL_ST],
- f[MAIL_ZIP],
- f[CLASS],
- f[P_CALL]
- );
- }
- else
- {
- fprintf(sp[i],"%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s\n",
- f[CALL],
- f[LNAME],
- f[FNAME],
- f[MI],
- f[JR],
- f[DOB],
- f[MAIL_STR],
- f[MAIL_CITY],
- f[MAIL_ST],
- f[MAIL_ZIP],
- f[CLASS]
- );
- }
-
- recs++;
- }
-
- fclose(fp);
- for (i=0; i<NST; i++)
- fclose(sp[i]);
-
- printf("\n%d records processed\n",recs);
- exit(0);
- }
-
-
- mk_fields(s,f)
- char *s;
- char *f[];
- {
- int i;
- char *p;
-
- if (p = strchr(s,'\n'))
- *p = '\0';
- i = 0;
- f[i] = s;
- while (*s)
- {
- if (*s == '|')
- {
- *s++ = '\0';
- f[++i] = s;
- }
- else
- s++;
- }
- }
-
-